from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from uuid import UUID, uuid4
from datetime import datetime
from models.base import Base
from pydantic import BaseModel, Field, constr, EmailStr


class FlowSchema(Base):
    __tablename__ = "flows"

    id: UUID = Column(String(50), primary_key=True, unique=True, nullable=False)
    name = Column(String(25), unique=False, nullable=False)
    description = Column(String(400), unique=True, nullable=False)
    config = Column(String(50), unique=False, nullable=False)
    state = Column(Integer, nullable=False, default=0)
    nodes = Column(String, nullable=False)
    create_time: datetime = Column()
    create_by: str = Column()
    update_time: datetime = Column()
    update_by: str = Column()


class FlowCreate(BaseModel):
    id: UUID = Field(primary_key=True, unique=True, nullable=False)
    name: str = Field(max_length=50, unique=True, nullable=False)
    description: str = Field(max_length=400, unique=True, nullable=False)


class FlowUpdate(FlowCreate):
    config: str
    state: int
    nodes: str
    create_time: datetime
    update_time: datetime
    update_by: str
    create_by: str


class Flow(FlowUpdate):
    id: UUID = Field(primary_key=True, unique=True, nullable=False)
